<template>
  <div class="container">
    <el-form :model="searchList" ref="searchList" size="normal">
      <el-row :gutter="20">
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-date-picker v-model="searchList.apply_batch" type="year" value-format="yyyy" size="normal"
              placeholder="选择申报批次" class="wid">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchList.project_name" placeholder="项目名称" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <div class="right">
            <el-button type='primary' size='medium' @click='search' :loading="loading">查询</el-button>
            <el-button type="primary" size="medium" @click="handleExpand" :loading="loading">
              <i :class="isExpand?'el-icon-remove-outline':'el-icon-circle-plus-outline'"></i>
              {{isExpand?'关闭全部行':'展开全部行'}}
            </el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data='tableData' border stripe :height='offsetHeight' v-loading='loading' ref='table' row-key="id"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column label='名称' min-width='80' align='left' header-align="center" show-overflow-tooltip tree>
        <template slot-scope='{row}'>
          {{row.name}}
        </template>
      </el-table-column>
      <el-table-column prop="company_name" label="创建部门" align='center' width="150">
      </el-table-column>
      <el-table-column label='申请金额' align='center' width="150">
        <template slot-scope='{row}'>
          <span v-if="row.grade =='1'">{{row.pr_service_amount ? row.pr_service_amount.toFixed(4):'0' }}</span>
          <span v-else-if="row.grade =='2'">{{row.pa_service_amount ? row.pa_service_amount.toFixed(4):'0' }}</span>
          <span v-else-if="row.grade =='3'">{{row.su_service_amount ? row.su_service_amount.toFixed(4):'0' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="find_check_amount" label="中标金额" align='center' width="100">
      </el-table-column>
      <el-table-column prop="bid_unit_name" label="中标单位" align='center' width="100">
      </el-table-column>
      <el-table-column label='操作' width='300' align='center'>
        <template slot-scope='{row}'>
          <template v-if="row.grade=='1'">
            <el-button-group>
              <el-button type="green" size="mini" @click="checkHistory(row.id)">查看审核意见</el-button>
            </el-button-group>
          </template>
          <template v-if="row.grade=='2'">
            <el-button-group>
              <el-button type="success" size="mini" @click="bidInfo(row)">查看中标信息</el-button>
            </el-button-group>
          </template>
          <template v-else-if="row.grade=='3'">
            <el-button-group>
              <el-button type="green" size="mini" @click="toIt(row)">查看IT资产及服务</el-button>
              <el-button type="warning" size="mini" @click="lookTargetVar(row.id)">招标技术参数</el-button>
            </el-button-group>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <!-- 招标技术参数信息 -->
    <el-drawer title="招标技术参数" :visible.sync="targetVarShow" size="70%" :destroy-on-close="true"
      :wrapperClosable="false">
      <target-var-item ref="targetVar" @cancel="cancel" @init="init" :targetVarParams="targetVarParams" :switch="false">
      </target-var-item>
    </el-drawer>
    <!-- 项目上报咨询机构 -->
    <el-dialog title="项目上报" :visible.sync="historyShow" width="50%" @close="cancel" :destroy-on-close="true">
      <report :project-id="projectId"></report>
    </el-dialog>
    <!-- 中标信息 -->
    <el-dialog title="中标信息" :visible.sync="bidShow" width="50%" @close="cancel" :destroy-on-close="true">
      <el-form :model="bidList" label-position="top" ref="bidList" size="normal">
        <el-row :gutter="20">
          <el-col :span="12" :offset="0">
            <el-form-item label="包组预算金额">
              <el-input v-model="bidList.plan_amount">
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" :offset="0">
            <el-form-item label="中标金额">
              <el-input v-model="bidList.win_bid_amount">
                <template slot="append">万元</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :offset="0">
            <el-form-item label="中标单位">
              <el-select v-model="bidList.win_bid_company_code" value-key="bid_unit" clearable class="wid">
                <el-option v-for="item in bidType" :key="item.value" :label="item.value" :value="item.label">
                  {{item.value}}——{{item.label}}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12" :offset="0">
            <up-load titleName="中标文件" :size="50" v-model="bidList.audit_report_url">
            </up-load>
          </el-col> -->
        </el-row>
        <div class="center">
          <el-button type="danger" size="default" @click="cancel">取消</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>

import TargetVarItem from '@/components/Bid/TargetVar.vue'
import Report from './report.vue'
import UpLoad from '@/components/Upload'
export default {
  name: 'BidEnsureNoFinish',
  components: {
    TargetVarItem, Report, UpLoad
  },
  props: {
    switch: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data () {
    // 获取当前年份
    let now = new Date().getFullYear().toString()
    return {
      offsetHeight: document.documentElement.clientHeight - 250,
      loading: false,
      saveLoading: false,
      searchList: {
        apply_batch: now
      },
      tableData: [],
      isExpand: false,
      targetVarShow: false,
      targetVarParams: {},
      projectId: '',
      historyShow: false,
      bidList: {},
      bidShow: false,
      bidType: [],
      bidType1: [],
      unitParams: {},
    }
  },
  created () {

  },
  mounted () {
    this.bidInit()
    this.init()
  },
  methods: {
    async bidInit () {
      const res = await this.$http('yqBidType', {
        requestType: 'get',
      })
      res.forEach(item => {
        this.bidType1[item.label] = item.value
      })
      this.bidType = res

    },
    async init () {
      this.loading = true
      const res = await this.$http('blockList', {
        del_flag: '0',
        order: "ensure_code",
        source: '2',
        del_flag: "0",
        ...this.searchList
      })
      res.forEach(item => {
        if (item.bid_unit) {
          item.bid_unit_name = this.bidType1[item.bid_unit]
        }
      })
      this.tableData = res
      this.loading = false
    },
    search () {
      this.init()
    },
    checkHistory (id) {
      this.projectId = id
      this.historyShow = true
    },
    lookTargetVar (id) {
      this.targetVarParams = {
        id: id,
      }
      this.targetVarShow = true
    },
    toIt (item) {
      sessionStorage.setItem("bidInfo",
        JSON.stringify({
          id: item.id,
          source: '2',
          titleName: item.name + '——' + item.package_name + '——' + item.project_name,
        })
      );
      this.$emit('toIt', this.switch, 'noFinish');
    },
    async bidInfo (item) {
      this.bidList = {
        id: item.id,
        plan_amount: item.plan_amount,
        win_bid_amount: item.win_bid_amount,
        win_bid_company_code: item.win_bid_company_code
      }
      this.bidShow = true
    },
    async save () {
      this.$confirm('是否保存', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async action => {
        this.saveLoading = true
        const res = await this.$http('blockPackageUp', {
          ...this.bidList
        })
        this.$tips.success(res.errmsg)
        this.saveLoading = false
        this.cancel()
        this.init()
      }).catch(() => {

      });
    },
    cancel () {
      this.targetVarShow = false
      this.targetVarParams = {}
      this.historyShow = false
      this.bidList = {}
      this.bidShow = false
    },
    // 是否展开table(展开与折叠切换)
    handleExpand () {
      this.isExpand = !this.isExpand
      this.$nextTick(() => {
        this.forArr(this.tableData, this.isExpand)
      })
    },
    // 遍历
    forArr (arr, isExpand) {
      arr.forEach(i => {
        // toggleRowExpansion(i, isExpand)用于多选表格，切换某一行的选中状态，如果使用了第二个参数，则是设置这一行选中与否（selected 为 true 则选中）
        this.$refs.table.toggleRowExpansion(i, isExpand)
        if (i.children) {
          this.forArr(i.children, isExpand)
        }
      })
    },
  },
  computed: {

  },
}
</script>
<style lang='scss' scoped>
</style>